home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Catalog Service Access Module / DTS Sample CSAM / Src / DETUtilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-22  |  12.1 KB  |  530 lines  |  [TEXT/KAHL]

  1. /*
  2.  * DETUtilities.h
  3.  * Copyright © 1992 Apple Computer Inc. All Rights Reserved.
  4.  *
  5.  * This is a collection of utility functions that simplify
  6.  * programming OCE Directory Templates (CSAM) files. They
  7.  * provide access to template properties and a few other
  8.  * common bits of information. These functions are independent
  9.  * of DTS Sample CSAM.
  10.  */
  11.  
  12. #include "DETUtilities.h"
  13. #include <Errors.h>
  14. #ifndef LogErrorX
  15. #include "Audit.h"
  16. #ifndef kCSAMCreatorID
  17. #define kCSAMCreatorID    'Pdsm'
  18. #elif kCSAMCreatorID != 'Pdsm'
  19.     << error, the above won't work >>
  20. #endif
  21. #define LogErrorX(who, status) do {                        \
  22.         if (status != noErr) {                            \
  23.             AuditStatusLocation(                        \
  24.                 GetAuditPtr(kCSAMCreatorID),            \
  25.                 who, status                                \
  26.             );                                            \
  27.         }                                                \
  28.     } while (0)
  29. #endif
  30.  
  31. /*
  32.  * Add a string to the Directory menu.
  33.  */
  34. pascal OSErr
  35. AddToMenu(
  36.         DETCallBlockPtr            callBlockPtr,
  37.         short                    property,
  38.         short                    parameter,
  39.         RString                    *text,
  40.         Boolean                    isSeparator
  41.     )
  42. {
  43.         OSErr                    status;
  44.         DETCallBackBlock        cbb;
  45.         typedef struct RString1 {
  46.             RStringHeader
  47.             Byte                body[sizeof (Byte)];
  48.         } RString1;
  49.         RString1                separator;
  50.         
  51.         
  52.         cbb.addMenu.reqFunction = kDETcmdAddMenu;
  53.         cbb.addMenu.property = property;
  54.         cbb.addMenu.target.selector = kDETSelf;
  55.         if (isSeparator == FALSE)
  56.             cbb.addMenu.name = text;
  57.         else {
  58.             separator.charSet = smRoman;
  59.             separator.dataLength = sizeof (Byte);
  60.             separator.body[0] = '-';
  61.             cbb.addMenu.name = (RString *) &separator;
  62.         }
  63.         cbb.addMenu.parameter = parameter;
  64.         cbb.addMenu.addAfter = -1;
  65.         status = CallBackDET(callBlockPtr, &cbb);
  66.         LogErrorX('DAMu', status);
  67.         return (status);
  68. }
  69.  
  70. /*
  71.  * Add/change an item to the template property database.
  72.  *        property                The property to add
  73.  *        newValue                A pointer to the datum
  74.  *        newValueSize            The size of the datum
  75.  *        markAsChanged            Mark database "changed"
  76.  * This function does the actual database manipulation.
  77.  * Normally, programs call SetBinaryProperty, SetNumProperty,
  78.  * or SetRStringProperty to set particular data types.
  79.  *
  80.  * Note: this assumes that all the new values are in the same
  81.  * position for Number, Binary, and RString properties
  82.  */
  83. pascal OSErr
  84. SetPropertyCommon(
  85.         DETCallBlockPtr            callBlockPtr,
  86.         DETCallFunctions        function,
  87.         short                    property,
  88.         void                    *newValue,
  89.         Size                    newValueSize,
  90.         Boolean                    markAsChanged
  91.     )
  92. {
  93.         OSErr                    status;
  94.         DETCallBackBlock        cbb;
  95.         
  96.         cbb.setPropertyBinary.reqFunction = function;
  97.         cbb.setPropertyBinary.property = property;
  98.         cbb.setPropertyBinary.target.selector = kDETSelf;
  99.         cbb.setPropertyBinary.newValue = newValue;
  100.         cbb.setPropertyBinary.newValueSize = newValueSize;    
  101.         status = CallBackDET(callBlockPtr, &cbb);
  102.         LogErrorX('DSPC', status);
  103.         if (status == noErr && markAsChanged) {
  104.             status = SetPropertyChanged(callBlockPtr, property, true);
  105.             LogErrorX('DSPC', status);
  106.         }
  107.         return (status);
  108. }
  109.  
  110. /*
  111.  * Add/change a numeric property.
  112.  * See SetPropertyCommon for the common parameters.
  113.  *        newValue                The property value.
  114.  */
  115. pascal OSErr
  116. SetNumProperty(
  117.         DETCallBlockPtr            callBlockPtr,
  118.         short                    property,
  119.         long                    newValue,
  120.         Boolean                    markAsChanged
  121.     )
  122. {
  123.         OSErr                    status;
  124.         
  125.         status = SetPropertyCommon(
  126.                     callBlockPtr,
  127.                     kDETcmdSetPropertyNumber,
  128.                     property,
  129.                     (void *) newValue,
  130.                     0,
  131.                     markAsChanged
  132.                 );
  133.         return (status);
  134. }
  135.  
  136. /*
  137.  * Add/change a binary (untyped) property.
  138.  * See SetPropertyCommon for the common parameters.
  139.  *        newValue                -> the new datum
  140.  *        newValueSize            Datum size
  141.  */
  142. pascal OSErr
  143. SetBinaryProperty(
  144.         DETCallBlockPtr            callBlockPtr,
  145.         short                    property,
  146.         Ptr                        newValue,
  147.         Size                    newValueSize,
  148.         Boolean                    markAsChanged
  149.     )
  150. {
  151.         OSErr                    status;
  152.     
  153.         status = SetPropertyCommon(
  154.                     callBlockPtr,
  155.                     kDETcmdSetPropertyBinary,
  156.                     property,
  157.                     newValue,
  158.                     newValueSize,
  159.                     markAsChanged
  160.                 );
  161.         return (status);
  162. }
  163.  
  164. /*
  165.  * Add/change a RString property.
  166.  * See SetPropertyCommon for the common parameters.
  167.  *        newValue                The new string contents
  168.  */
  169. pascal OSErr
  170. SetRStringProperty(
  171.         DETCallBlockPtr            callBlockPtr,
  172.         short                    property,
  173.         RString                    *newValue,
  174.         Boolean                    markAsChanged
  175.     )
  176. {
  177.     OSErr                    status;
  178.  
  179.     status = SetPropertyCommon(
  180.                 callBlockPtr,
  181.                 kDETcmdSetPropertyRString,
  182.                 property,
  183.                 newValue,
  184.                 0,
  185.                 markAsChanged
  186.             );
  187.     return (status);
  188. }
  189.  
  190. /*
  191.  * Return the value of a numeric property
  192.  *        result                    Address of the desired value
  193.  */
  194. pascal OSErr
  195. GetNumProperty(
  196.         DETCallBlockPtr            callBlockPtr,
  197.         short                    property,
  198.         long                    *result
  199.     )
  200. {
  201.         OSErr                    status;
  202.         DETCallBackBlock        cbb;
  203.         
  204.         cbb.getPropertyNumber.reqFunction = kDETcmdGetPropertyNumber;
  205.         cbb.getPropertyNumber.property = property;
  206.         cbb.getPropertyNumber.target.selector = kDETSelf;
  207.         status = CallBackDET(callBlockPtr, &cbb);
  208.         LogErrorX('DGNP', status);
  209.         *result = cbb.getPropertyNumber.propertyValue;
  210.         return (status);
  211. }
  212.  
  213. pascal OSErr
  214. GetBinaryProperty(
  215.         DETCallBlockPtr            callBlockPtr,
  216.         short                    property,
  217.         Handle                    *result
  218.     )
  219. {
  220.         OSErr                    status;
  221.         DETCallBackBlock        cbb;
  222.         
  223.         cbb.getPropertyBinary.reqFunction = kDETcmdGetPropertyBinary;
  224.         cbb.getPropertyBinary.property = property;
  225.         cbb.getPropertyBinary.target.selector = kDETSelf;
  226.         status = CallBackDET(callBlockPtr, &cbb);
  227.         LogErrorX('DGBP', status);
  228.         *result = cbb.getPropertyBinary.propertyValue;
  229.         return (status);
  230. }
  231.  
  232. /*
  233.  * Return the value of a RString property
  234.  *        result                    Gets a pointer to the RString value
  235.  */
  236. pascal OSErr
  237. GetRStringProperty(
  238.         DETCallBlockPtr            callBlockPtr,
  239.         short                    property,
  240.         RString                    ***result
  241.     )
  242. {
  243.         OSErr                    status;
  244.         DETCallBackBlock        cbb;
  245.         
  246.         cbb.getPropertyRString.reqFunction = kDETcmdGetPropertyRString;
  247.         cbb.getPropertyRString.property = property;
  248.         cbb.getPropertyRString.target.selector = kDETSelf;
  249.         status = CallBackDET(callBlockPtr, &cbb);
  250.         LogErrorX('DGRP', status);
  251.         *result = cbb.getPropertyRString.propertyValue;
  252.         return (status);
  253. }
  254.  
  255. pascal OSErr
  256. GetBinaryPropertySize(
  257.         DETCallBlockPtr            callBlockPtr,
  258.         short                    property,
  259.         Size                    *size
  260.     )
  261. {
  262.         OSErr                    status;
  263.         DETCallBackBlock        cbb;
  264.         
  265.         cbb.getPropertyBinarySize.reqFunction = kDETcmdGetPropertyBinarySize;
  266.         cbb.getPropertyBinarySize.property = property;
  267.         cbb.getPropertyBinarySize.target.selector = kDETSelf;
  268.         status = CallBackDET(callBlockPtr, &cbb);
  269.         LogErrorX('DGPS', status);
  270.         *size = cbb.getPropertyBinarySize.propertyBinarySize;
  271.         return (status);
  272. }
  273.  
  274. /*
  275.  * Mark property "dirty"
  276.  */
  277. pascal OSErr
  278. DirtyProperty(
  279.         DETCallBlockPtr            callBlockPtr,
  280.         short                    property
  281.     )
  282. {
  283.         OSErr                    status;
  284.         DETCallBackBlock        cbb;
  285.         
  286.         cbb.dirtyProperty.reqFunction = kDETcmdDirtyProperty;
  287.         cbb.dirtyProperty.property = property;
  288.         cbb.dirtyProperty.target.selector = kDETSelf;
  289.         status = CallBackDET(callBlockPtr, &cbb);
  290.         LogErrorX('Dirt', status);
  291.         return (status);
  292. }
  293.  
  294. /*
  295.  * Mark property "changed" if the flag is TRUE.
  296.  */
  297. pascal OSErr
  298. SetPropertyChanged(
  299.         DETCallBlockPtr            callBlockPtr,
  300.         short                    property,
  301.         Boolean                    isPropertyChanged
  302.     )
  303. {
  304.         OSErr                    status;
  305.         DETCallBackBlock        cbb;
  306.         
  307.         cbb.setPropertyChanged.reqFunction = kDETcmdSetPropertyChanged;
  308.         cbb.setPropertyChanged.property = property;
  309.         cbb.setPropertyChanged.target.selector = kDETSelf;
  310.         cbb.setPropertyChanged.propertyChanged = isPropertyChanged;
  311.         status = CallBackDET(callBlockPtr, &cbb);
  312.         LogErrorX('DSPC', status);
  313.         return (status);
  314. }
  315.  
  316. /*
  317.  * Return a pointer to the DSSSpec for this template
  318.  */
  319. pascal OSErr
  320. GetMyDSSpec(
  321.         DETCallBlockPtr            callBlockPtr,
  322.         short                    *refNum,
  323.         PackedDSSpec            ***pDsSpec
  324.     )
  325. {
  326.         OSErr                    status;
  327.         DETCallBackBlock        cbb;
  328.         
  329.         cbb.getDSSpec.reqFunction = kDETcmdGetDSSpec;
  330.         cbb.getDSSpec.target.selector = kDETSelf;
  331.         status = CallBackDET(callBlockPtr, &cbb);
  332.         LogErrorX('GDSp', status);
  333.         *pDsSpec = cbb.getDSSpec.dsSpec;
  334.         *refNum = cbb.getDSSpec.refNum;            
  335.         return (status);
  336. }
  337.  
  338. /*
  339.  * Get the number of items selected by the user.
  340.  */
  341. pascal OSErr
  342. GetNumSelectedItems(
  343.         DETCallBlockPtr            callBlockPtr,
  344.         long                    *result
  345.     )
  346. {
  347.         OSErr                    status;
  348.         DETCallBackBlock        cbb;
  349.         
  350.         cbb.selectedSublistCount.reqFunction = kDETcmdSelectedSublistCount;
  351.         cbb.selectedSublistCount.target.selector = kDETSelf;
  352.         status = CallBackDET(callBlockPtr, &cbb);
  353.         LogErrorX('GNSI', status);
  354.         *result = cbb.selectedSublistCount.count;
  355.         return (status);
  356. }
  357.  
  358. /*
  359.  * GetNthSelectedItem allows the program to iterate
  360.  * through the items selected by a user.
  361.  */
  362. pascal OSErr
  363. GetNthSelectedItem(
  364.         DETCallBlockPtr            callBlockPtr,
  365.         long                    itemNumber,
  366.         PackedDSSpec            ***pDsSpec,
  367.         short                    *refNum
  368.     )
  369. {
  370.         OSErr                    status;
  371.         DETCallBackBlock        cbb;
  372.         
  373.         cbb.getDSSpec.reqFunction = kDETcmdGetDSSpec;
  374.         cbb.getDSSpec.target.selector = kDETSelectedSublistItem;
  375.         cbb.getDSSpec.target.aspectName = NULL;
  376.         cbb.getDSSpec.target.itemNumber = itemNumber;
  377.         status = CallBackDET(callBlockPtr, &cbb);
  378.         LogErrorX('GNth', status);
  379.         *pDsSpec = cbb.getDSSpec.dsSpec;
  380.         *refNum = cbb.getDSSpec.refNum;
  381.         return (status);
  382. }
  383.  
  384. pascal OSErr
  385. OpenDSSpec(
  386.         DETCallBlockPtr            callBlockPtr,
  387.         PackedDSSpec            *dsSpec
  388.     )
  389. {
  390.         OSErr                    status;
  391.         DETCallBackBlock        cbb;
  392.         
  393.         cbb.openDSSpec.reqFunction = kDETcmdOpenDSSpec;
  394.         cbb.openDSSpec.dsSpec = dsSpec;
  395.         status = CallBackDET(callBlockPtr, &cbb);
  396.         LogErrorX('ODSS', status);
  397.         return (status);
  398. }
  399.  
  400. pascal OSErr
  401. GetMyFSSpec(
  402.         DETCallBlockPtr            callBlockPtr,
  403.         FSSpec                    *fsSpecPtr
  404.     )
  405. {
  406.         OSErr                    status;
  407.         DETCallBackBlock        cbb;
  408.         
  409.         cbb.getTemplateFSSpec.reqFunction = kDETcmdGetTemplateFSSpec;
  410.         cbb.getTemplateFSSpec.target.selector = kDETSelf;
  411.         status = CallBackDET(callBlockPtr, &cbb);
  412.         LogErrorX('GFSp', status);
  413.         if (status == noErr)
  414.             *fsSpecPtr = cbb.getTemplateFSSpec.fsSpec;
  415.         return (status);
  416. }
  417.  
  418. pascal OSErr
  419. GetMenuItemRString(
  420.         DETCallBlockPtr            callBlockPtr,
  421.         short                    property,
  422.         long                    parameter,
  423.         RString                    ***result
  424.     )
  425. {
  426.         OSErr                    status;
  427.         DETCallBackBlock        cbb;
  428.         
  429.         cbb.menuItemRString.reqFunction = kDETcmdMenuItemRString;
  430.         cbb.menuItemRString.property = property;
  431.         cbb.menuItemRString.target.selector = kDETSelf;
  432.         cbb.menuItemRString.itemParameter = parameter;
  433.         status = CallBackDET(callBlockPtr, &cbb);
  434.         LogErrorX('GMRS', status);
  435.         *result = cbb.menuItemRString.rString;
  436.         if (status == paramErr)
  437.             status = noErr;
  438.         return (status);
  439. }
  440.  
  441. pascal OSErr
  442. RequestSync(
  443.         DETCallBlockPtr            callBlockPtr
  444.     )
  445. {
  446.         OSErr                    status;
  447.         DETCallBackBlock        cbb;
  448.         
  449.         cbb.requestSync.reqFunction = kDETcmdRequestSync;
  450.         cbb.requestSync.target.selector = kDETSelf;
  451.         status = CallBackDET(callBlockPtr, &cbb);
  452.         LogErrorX('Sync', status);
  453.         return (status);
  454. }
  455.  
  456. pascal OSErr
  457. SaveProperty(
  458.         DETCallBlockPtr            callBlockPtr,
  459.         long                    property
  460.     )
  461. {
  462.         OSErr                    status;
  463.         DETCallBackBlock        cbb;
  464.         
  465.         cbb.saveProperty.reqFunction = kDETcmdSaveProperty;
  466.         cbb.saveProperty.property = property;
  467.         cbb.saveProperty.target.selector = kDETSelf;
  468.         status = CallBackDET(callBlockPtr, &cbb);
  469.         LogErrorX('SavP', status);
  470.         return (status);
  471. }
  472.  
  473. pascal OSErr
  474. GetCustomViewBounds(
  475.         DETCallBlockPtr            callBlockPtr, 
  476.         short                    property, 
  477.         Rect                    *bounds
  478.     )
  479. {
  480.         OSErr                    status;
  481.         DETCallBackBlock        cbb;
  482.         
  483.         cbb.getCustomViewBounds.reqFunction = kDETcmdGetCustomViewBounds;
  484.         cbb.getCustomViewBounds.property = property;
  485.         cbb.getCustomViewBounds.target.selector = kDETSelf;
  486.         status = CallBackDET(callBlockPtr, &cbb);
  487.         LogErrorX('GVbd', status);
  488.         *bounds = cbb.getCustomViewBounds.bounds;
  489.         return (status);
  490. }
  491.  
  492. pascal OSErr
  493. GetPropertyEditable(
  494.         DETCallBlockPtr            callBlockPtr,
  495.         short                    property,
  496.         Boolean                    *isEditable
  497.     )
  498. {
  499.         OSErr                    status;
  500.         DETCallBackBlock        cbb;
  501.         
  502.         cbb.getPropertyEditable.reqFunction = kDETcmdGetPropertyEditable;
  503.         cbb.getPropertyEditable.property = property;
  504.         cbb.getPropertyEditable.target.selector = kDETSelf;
  505.         status = CallBackDET(callBlockPtr, &cbb);
  506.         LogErrorX('GPEd', status);
  507.         *isEditable = cbb.getPropertyEditable.propertyEditable;
  508.         return (status);
  509. }
  510.  
  511. pascal OSErr
  512. SetPropertyEditable(
  513.         DETCallBlockPtr            callBlockPtr,
  514.         short                    property,
  515.         Boolean                    isEditable
  516.     )
  517. {
  518.         OSErr                    status;
  519.         DETCallBackBlock        cbb;
  520.         
  521.         cbb.setPropertyEditable.reqFunction = kDETcmdSetPropertyEditable;
  522.         cbb.setPropertyEditable.property = property;
  523.         cbb.setPropertyEditable.target.selector = kDETSelf;
  524.         cbb.setPropertyEditable.propertyEditable = isEditable;
  525.         status = CallBackDET(callBlockPtr, &cbb);
  526.         LogErrorX('SPed', status);
  527.         return (status);
  528. }
  529.  
  530.